<template>
  <div class="myAssetsHome">
    <header-btn  :btnList='record_list_data' :tabIndex='tabIndex' @changetabIndex='tabIndexChange' />
    <!-- 记录列表 -->
    <div class="myAssetsContent" v-if="tabIndex==1"> 
        <div class="table-vue">
             <assembly-Integration :formInline='formInline' :btnList="btnList" @search="onSubmit" @btnListClick="btnListClick" />
            <lpj-table-vue :baseNum='paginationMes.per_page*(paginationMes.current_page-1)' :tableHeaderData="tableHeaderData" :tableData="tableData"></lpj-table-vue>
        </div>
        <pagination align="right" v-if="paginationMes.total&&paginationMes.total>10"  :paginationMes="paginationMes" @sizeChangeFn="sizeChangeFn" @currentChangeFn="currentChangeFn"></pagination>
    </div>
    <!-- 报表 -->
    <!-- <report-form ref="reportForm"  v-if="tabIndex==0"></report-form> -->
  </div>
</template>
<script>
/* eslint-disable */
import {getConsumablesList} from "./api"
import Pagination from "@/components/Pagination"
import LpjTableVue from "@/components/LpjTableVue"
import headerBtn from "@/components/headerBtn"
import constObj from '@/config/const' /**表头常数 */
import reportForm from "./components/myReportForm"
import HeadSearchBox from '@/components/HeadSearchBox' /*头部搜索*/
import assemblyIntegration from "@/components/assemblyIntegration"/** 新版搜索框 */
export default {
  name: "myAssets",
  components:{ Pagination, LpjTableVue,headerBtn,reportForm,HeadSearchBox,assemblyIntegration },
  data() {
    return {
      /**头部记录信息 */
      record_list_data:[
         {num:'',content:'我的报表'},
         {num:'',content:'我的耗材'}
	  ],
      tabIndex:0,
      tableHeaderData:constObj.tableHeaderOfmyMeterials,
      tableData:[],/*table里的数据 */
      paginationMes:{per_page:10,current_page:1,totol:0}, /*分页 数据*/
      assetsDataList:[{}], /**耗材数据 */
      btnList:[
          {
              type:'batchTransfer',
              label:'批量转移'
          },
          {
              type:'batchTakeBack',
              label:'批量退还'
          },
      ],
      formInline:[ /**搜索框 */
          {type:'input',value:'f_name',label:'耗材名称',placeholder:'请输入内容',hide:false},
          {type:'input',value:'f_code',label:'耗材编码',placeholder:'请输入内容',hide:false},
          {type:'daterange',value:'time',label: '领用时间',hide:false},
      ],
    };
  },
  created() {
    this.tabIndex = Number(localStorage.curTabIndex||0)
    this.tabIndex==0?this.getDataFn():''
  },
  methods: {
    /**切换tabIndex */
    tabIndexChange(index){
      this.tabIndex = index
      localStorage.curTabIndex = index
      this.paginationMes={per_page:10,current_page:1,totol:0}, /*分页 数据*/
      index==0?this.getDataFn():''
    },
    /**获取耗材数据 */
    getDataFn(){
      getConsumablesList({num:this.paginationMes.per_page,page:this.paginationMes.current_page}).then(res=>{
        this.paginationMes = {total:Number(res.total),per_page:Number(res.per_page),current_page:Number(res.current_page)}
        this.tableData = res.data
      })
    },
    sizeChangeFn(val){
          this.paginationMes.current_page = 1
          this.paginationMes.per_page = val
          this.getDataFn()
    },
    currentChangeFn(val){
          this.paginationMes.current_page = val
          this.getDataFn()
    },
   btnListClick(item){
      console.log(item,'item')
      switch(item.type){
          case 'batchTransfer': // 批量转移
          console.log(item.label)
          break;
          case 'batchTakeBack': // 批量收回
          console.log(item.label)
          break;
      }
   },
   onSubmit(form,user,dept) {
       this.userArr = user
       this.deptArr = dept
       this.paginationMes.current_page = 1
       this.form = {
           ...this.form,
           ...form
       }
       this.getDataFn();
   },
  }
};
</script>
<style lang="stylus" scoped>
.myAssetsHome
  font-family "SourceHanSansCN-Regular"
  height 100%
  font-size 14px
  color #303133 
  .myAssetsContent
    margin 10px 0
    background-color #fff
    padding 30px
</style>